#include "log.h"
#include "settings.h"
#include <iostream>
#include <iomanip>
#include <cstdarg>
#include <cstdio>
#include <ctime>

void log(logLevel level, const char *txt, ...)
{
    if (getInt("LOG_LEVEL") < level)
        return;

    va_list argList;
    char txtBuffer[1024];
    char timeBuffer[9];
    time_t rawTime;
    struct tm* timeInfo;

    va_start(argList, txt);
    vsnprintf(txtBuffer, 1024, txt, argList);
    va_end(argList);

    time(&rawTime);
    timeInfo = localtime(&rawTime);
    strftime(timeBuffer, 9, "%H:%M:%S", timeInfo);

    std::cout << timeBuffer << " " << std::setw(10) << std::left << levelString[level] << txtBuffer;
}
